package com.jdz.gxq.info.admin.landclear.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import com.jdz.gxq.info.admin.landclear.bo.Landclear;
import com.jdz.gxq.info.admin.landclear.form.AddLandclearForm;
import com.jdz.gxq.info.admin.landclear.service.LandclearService;
import com.jdz.gxq.info.common.action.CommonAction;

public class AddLandclearAction extends CommonAction {

	private LandclearService landclearService = null;
	 
	public ActionForward doExecute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws java.lang.Exception {
		
		AddLandclearForm addLandclearFrom = (AddLandclearForm) form;
		
		Landclear landclear = addLandclearFrom.getLandclear();

		// landclear名重复验证(其他后台逻辑验证也类似处理)
		if (!landclearService.checkLandclearName(landclear, 1)) {
			ActionMessages messages = new ActionMessages();
			messages.add("landclear.enterpriseName", new ActionMessage("error.landclearNameExisted"));
			addErrors(request, messages);
			return mapping.getInputForward();
		}
		
		landclear.setModifiedBy(getUserId(request));
		
		landclearService.insertLandclear(landclear);

		return mapping.findForward("success");
	}

	public void setLandclearService(LandclearService landclearService) {
		this.landclearService = landclearService;
	}
}

